﻿using System;
using Domain.MainModule.CustomerCompanies;
using Domain.MainModule.Entities;
using Infraestructure.CrossCutting.Logging;
using Infraestructure.Data.MainModule.UnitOfWork;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests
{
    
    
    /// <summary>
    ///This is a test class for CustomerCompanyRepositoryTest and is intended
    ///to contain all CustomerCompanyRepositoryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CustomerCompanyRepositoryTest : CustomRepositoryTestsBase<CustomerCompany, User>
    {

        private TestContext testContextInstance;

        public override System.Linq.Expressions.Expression<Func<CustomerCompany, bool>> FilterExpression
        {
            get { return a => a.UserId == TestConstants.Instance.CUSTOMER_COMPANY_ID; }
        }

        public override System.Linq.Expressions.Expression<Func<CustomerCompany, Guid>> OrderByExpression
        {
            get { return a => a.UserId; }
        }

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindCustomerCompany_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerCompanyRepository repository = new CustomerCompanyRepository(context, traceManager);

            //Act
            repository.FindCustomerCompany(null);
        }

        #region CustomerCompanyUserIdSpecification

        [TestMethod()]
        public void FindCustomerCompanyByUserId_Invoke_InvalidUserIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerCompanyRepository repository = new CustomerCompanyRepository(context, traceManager);
            CustomerCompany customerCompany;

            Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            CustomerCompanyUserIdSpecification spec = new CustomerCompanyUserIdSpecification(invalidId);

            //Act
            customerCompany = repository.FindCustomerCompany(spec);

            //Assert
            Assert.IsNull(customerCompany);
        }

        /// <summary>
        ///A test for FindCustomerCompany
        ///</summary>
        [TestMethod()]
        public void FindCustomerCompanyByUserId_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerCompanyRepository repository = new CustomerCompanyRepository(context, traceManager);
            CustomerCompany actual;
            CustomerCompanyUserIdSpecification specification = new CustomerCompanyUserIdSpecification(TestConstants.Instance.CUSTOMER_COMPANY_ID);

            //Act
            actual = repository.FindCustomerCompany(specification);

            //Assert 
            Assert.IsNotNull(actual);
        }

        #endregion

        #region CustomerCompanyMembershipUserIdSpecification

        [TestMethod()]
        public void FindCustomerCompanyByMembershipUserId_Invoke_InvalidUserIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerCompanyRepository repository = new CustomerCompanyRepository(context, traceManager);
            CustomerCompany customerCompany;

            Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            CustomerCompanyMembershipUserIdSpecification spec = new CustomerCompanyMembershipUserIdSpecification(invalidId);

            //Act
            customerCompany = repository.FindCustomerCompany(spec);

            //Assert
            Assert.IsNull(customerCompany);
        }

        /// <summary>
        ///A test for FindCustomerCompany
        ///</summary>
        [TestMethod()]
        public void FindCustomerCompanyByMembershipUserId_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerCompanyRepository repository = new CustomerCompanyRepository(context, traceManager);
            CustomerCompany actual;
            CustomerCompanyMembershipUserIdSpecification specification = new CustomerCompanyMembershipUserIdSpecification(TestConstants.Instance.MEMBERSHIP_USER_ID);

            //Act
            actual = repository.FindCustomerCompany(specification);

            //Assert 
            Assert.IsNotNull(actual);
        }

        #endregion
    }
}
